import {defineConfig} from 'vite'
import vue from '@vitejs/plugin-vue'
import importToCDN, {autoComplete} from 'vite-plugin-cdn-import'
import viteCompression from 'vite-plugin-compression';
import legacy from '@vitejs/plugin-legacy';
import visualizer from "rollup-plugin-visualizer";

const plugins = [];

    // 打包依赖展示
    plugins.push(
        visualizer({
            open: true,
            gzipSize: true,
            brotliSize: true,
        })
    );

// https://vitejs.dev/config/
export default defineConfig({
    plugins: [
        vue(),
        importToCDN({
            modules: [
                {
                    name: 'vue',
                    var: 'Vue',
                    path: 'https://unpkg.com/vue@3.2.21/dist/vue.global.prod.js'
                },
                {
                    name: 'ant-design-vue',
                    var: 'antd',
                    path: [
                        'https://unpkg.com/ant-design-vue@2.2.8/dist/antd.min.js',
                    ],
                    css: [
                        'https://unpkg.com/ant-design-vue@2.2.8/dist/antd.min.css',
                    ],
                },
                {
                    name: 'vuex',
                    var: 'Vuex',
                    path: 'https://unpkg.com/vuex@4.0.2/dist/vuex.global.prod.js'
                },
                {
                    name: 'accounting',
                    var: 'accounting',
                    path: 'https://unpkg.com/accounting@0.4.1/accounting.min.js'
                },
                {
                    name: 'dayjs',
                    var: 'dayjs',
                    path: 'https://unpkg.com/dayjs@1.10.5/dayjs.min.js'
                },
                {
                    name: 'vue-router',
                    var: 'VueRouter',
                    path: 'https://unpkg.com/vue-router@4.0.12/dist/vue-router.global.prod.js'
                },
                {
                    name: 'axios',
                    var: 'axios',
                    path: 'https://unpkg.com/axios@0.21.1/dist/axios.min.js'
                },
                // autoComplete('axios'),
            ]
        }),
        // legacy({
        //     targets: ['> 1%, last 1 version']
        // }),
        viteCompression({
            verbose: true,
            disable: false,
            algorithm: 'gzip',
            ext: '.gz'
        }),
        viteCompression({
            verbose: true,
            disable: false,
            algorithm: 'brotliCompress',
            ext: '.br'
        }),
        ...plugins
    ],
    base: './',
    resolve: {
        alias: {}
    },
    css:{
       preprocessorOptions:{
           less:{
               modifyVars:{
                   'primary-color': '#1677ff'
               },
               javascriptEnabled: true
           }
       }
    },
    build: {
        rollupOptions: {}
    }
})
